<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
welcome to my website
<table id="tab">
    <tr>
        <th>员工编号</th>
        <th>员工姓名</th>
        <th>员工性别</th>
        <th>员工学历</th>
        <th>入职日期</th>
        <th>出生日期</th>
        <th>员工薪水</th>
    </tr>

</table>

<script>
    //javascript : js
    //ajax - javascript - java方向  异步刷新
    let http = new XMLHttpRequest();
    http.open('get','/showAll',true);
    http.onreadystatechange = function () {
        // 0 1 2 3 4(完成)   http status  200成功
        if(http.readyState == 4 && http.status == 200){
            let data = JSON.parse(http.responseText);
            if(data.code == 200){
                let tab = document.getElementById('tab');
                for(let i = 0;i < data.data.length;i++){
                    let tr = tab.insertRow();

                    let td = tr.insertCell();
                    td.innerText = data.data[i].eid;

                    td = tr.insertCell();
                    td.innerText = data.data[i].ename;

                    td = tr.insertCell();
                    td.innerText = data.data[i].sex;

                    td = tr.insertCell();
                    td.innerText = data.data[i].edu;

                    td = tr.insertCell();
                    td.innerText = data.data[i].employed;

                    td = tr.insertCell();
                    td.innerText = data.data[i].birthday;

                    td = tr.insertCell();
                    td.innerText = data.data[i].salary;
                }
            }else{
                alert(data.msg);
            }
        }
    }
    http.send();
</script>


</body>
</html>